//
//  DMControllertwo.m
//  DMGME
//
//  Created by ihope99 on 15/8/27.
//  Copyright (c) 2015年 GYP. All rights reserved.
//

#import "DMMineWalletController.h"
#import "DMMineWalletCell.h"
#import "DMOrderDetail.h"
#import "DMMineViewCell.h"
#import "DMMineTwoViewCell.h"
#import "DMMineModel.h"
#import "DMTiXianViewController.h"
#import "DMTiXianRecordViewController.h"
#import <UMSocialCore/UMSocialCore.h>

#define  HeaderViewSize headerView.frame.size
#define  HeaderViewOrigin headerView.frame.origin
#define  WINDOWWIDTH [[UIScreen mainScreen] bounds].size.width
#define WINDOWHEIGHT [[UIScreen mainScreen] bounds].size.height
@interface DMMineWalletController ()
{
    UIImageView *_scrollLine;
    UIView *headerView;
    UIView *_alertView;
    UIView *_hug;
    NSDictionary *_walletDic;
    long int _num;
    NSString *_yuENoti;
    UILabel *_tishiLabel;
}
@property (nonatomic,strong)NSMutableArray *datas;
@property (nonatomic,strong)NSMutableArray *datas1;

@property (nonatomic,strong)UITableView *tableview;
@end

@implementation DMMineWalletController
-(void)viewWillAppear:(BOOL)animated
{
     [self dataRequest2];
     [self dataRequest];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _num = 200;

    self.title = @"我的钱包";
    [self AddLeftImageBtn:[UIImage imageNamed:@"fanhui_03 2"]target:self action:@selector(GoBack)];
    _datas = [NSMutableArray array];
    _datas1 = [NSMutableArray array];
    
    _walletDic = [NSDictionary dictionary];
    [self dataRequest];
       // 创建tableView
    [self createTableView];
    // Do any additional setup after loading the view.
    
    //注册通知
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateTableViewHeader:) name:@"yuE" object:nil];
    
   
}
#pragma mark 交易记录请求
-(void)dataRequest
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:[AFDownManager MD5String:@"%^&*dongmangoug!@#$order"] forKey:@"token"];
    [dict setValue:kkUserDict[@"id"] forKey:@"agent_id"];
    [dict setValue:@"order" forKey:@"action"];
    [self StartLoading];
    [AFDownManager POST:MyWalletNet parameters:dict success:^(id responseObject) {
        [self StopLoading];
        [_datas removeAllObjects];
//        NSLog(@"交易记录 == %@",responseObject);
        if ([responseObject[@"data"][@"listData"] count] != 0) {
            NSArray *arr = responseObject[@"data"][@"listData"];
            for (NSDictionary *dic in arr) {
                DMMineModel *dmModel = [[DMMineModel alloc] init];
                [dmModel setValuesForKeysWithDictionary:dic];
                [_datas addObject:dmModel];
                }
            [_tableview reloadData];
        }else
        {
            _tishiLabel.hidden = NO;
            
        
        }
    } failure:^(NSError *error) {
        [self StopLoading];
        [self showMsg:@"网络连接故障"];
//       NSLog(@"dataRequest error = %@",error);
    }];
}
#pragma mark 补贴记录请求
-(void)dataRequest1
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:[AFDownManager MD5String:@"%^&*dongmangoug!@#$subsidy"] forKey:@"token"];
    [dict setValue:kkUserDict[@"id"] forKey:@"agent_id"];
    [dict setValue:@"subsidy" forKey:@"action"];
   
    [self StartLoading];
    [AFDownManager POST:MyWalletNet parameters:dict success:^(id responseObject) {
//       NSLog(@"补贴记录%ulu",[responseObject[@"data"][@"listData"] count]);
        [self StopLoading];
        [_datas1 removeAllObjects];
//        _walletDic = responseObject[@"data"][@"wallet"];
        if ([responseObject[@"data"][@"listData"] count] == 0 || responseObject[@"data"][@"listData"] == nil) {
            _tishiLabel.hidden = NO;
        }else
        {
        for (NSDictionary *subDic in responseObject[@"data"][@"listData"]) {
            
      
        DMMineModel *dmModel = [[DMMineModel alloc] init];
        [dmModel setValuesForKeysWithDictionary:subDic];
        [_datas1 addObject:dmModel];
              }
        }
        [_tableview reloadData];
    } failure:^(NSError *error) {
        [self StopLoading];
        [self showMsg:@"网络连接故障"];
//        NSLog(@"dataRequest error = %@",error);

    }];
    
}
#pragma mark 全部金额请求
-(void)dataRequest2
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:[AFDownManager MD5String:@"%^&*dongmangoug!@#$"] forKey:@"token"];
    [dict setValue:kkUserDict[@"id"] forKey:@"agent_id"];
   
    [AFDownManager POST:MyAllMoney parameters:dict success:^(id responseObject) {
//        NSLog(@"全部金额==%@",responseObject);
       
        _walletDic = responseObject[@"data"];
        _yuENoti = _walletDic[@"balance"];
        [_tableview reloadData];
    } failure:^(NSError *error) {
       
        [self showMsg:@"网络连接故障"];
//        NSLog(@"dataRequest error = %@",error);
        
    }];
    
}
-(void)updateTableViewHeader:(NSNotification *)text
{
//    NSLog(@"-====%@",text.userInfo);
    float fl = [_walletDic[@"balance"] floatValue]-[text.userInfo[@"yuE"] floatValue];
    
    _yuENoti = [NSString stringWithFormat:@"%0.2f",fl];
    [_tableview reloadData];
}
- (void)createTableView
{

    _tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KWidth, KHeight) style:UITableViewStyleGrouped];
    _tableview.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.separatorStyle = UITableViewScrollPositionNone;
    [self.view addSubview:_tableview];
    [_tableview registerNib:[UINib nibWithNibName:@"DMMineViewCell" bundle:nil] forCellReuseIdentifier:@"Cell"];
    [_tableview registerNib:[UINib nibWithNibName:@"DMMineTwoViewCell" bundle:nil] forCellReuseIdentifier:@"Two"];

}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    headerView = [[UIView alloc] init];
    headerView.frame = CGRectMake(0, 0, KWidth, KHeight/7*3);
    headerView.backgroundColor = [UIColor whiteColor];
    //    CGSize HeaderViewSize = headerView.frame.size;
    //    CGPoint HeaderViewOrigin = headerView.frame.origin;
    UIView *lineView = [[UIView alloc] init];
    lineView.frame = CGRectMake(0, HeaderViewSize.height/7*6, KWidth, 1);
    lineView.backgroundColor = [UIColor grayColor];
    
    UILabel *tishiLab = [[UILabel alloc] initWithFrame:CGRectMake(15, lineView.frame.origin.y-45, KWidth-10, 21)];
    tishiLab.textColor = [UIColor grayColor];
    tishiLab.text = @"余额大于1元时才能提现,每天最多可提现10次。";
    [headerView addSubview:tishiLab];
    
    UIView *leftView1 = [[UIView alloc] init];
    leftView1.frame = CGRectMake(15, HeaderViewSize.height/9, 10, HeaderViewSize.height/10);
    leftView1.backgroundColor = ComColor;
    
    
    UIView *leftView2 = [[UIView alloc] init];
    leftView2.frame = CGRectMake(15, CGRectGetMaxY(leftView1.frame)+5, 10, HeaderViewSize.height/10);
    leftView2.backgroundColor = ComColor;
    
    UIView *leftView3 = [[UIView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(leftView2.frame)+5, 10, HeaderViewSize.height/10)];
    leftView3.backgroundColor = ComColor;
    
    UILabel *totalTradeLable = [[UILabel alloc] init];
    totalTradeLable.frame = CGRectMake(CGRectGetMaxX(leftView2.frame)+10, Y(leftView2), KWidth, HEIGHT(leftView2));
    
    UILabel *totalSubsidyLable = [[UILabel alloc] init];
    totalSubsidyLable.frame = CGRectMake(CGRectGetMaxX(leftView3.frame)+10, Y(leftView3), KWidth, HEIGHT(leftView3));
    if( _walletDic[@"order"] == nil|_walletDic[@"order"]== [NSNull null])
    {
        totalTradeLable.text = @"交易总额:￥0元";
        //
        
    }else
    {
     
//        NSLog(@"===%@",_walletDic[@"order"]);
        totalTradeLable.text = [NSString stringWithFormat:@"交易总额:￥%0.2f元",[_walletDic[@"order"] floatValue]];
        
    }
    if (_walletDic[@"subsidy"] == nil|_walletDic[@"subsidy"]== [NSNull null]) {
        totalSubsidyLable.text = @"累计补贴总额:￥0元";
    }
    
    else
    {
        totalSubsidyLable.text = [NSString stringWithFormat:@"累计补贴总额:￥%0.2f元",[_walletDic[@"subsidy"] floatValue]];
    }
    UILabel *leijibutieLable = [[UILabel alloc] init];
    leijibutieLable.frame = CGRectMake(CGRectGetMaxX(leftView1.frame)+10, Y(leftView1), KWidth, HEIGHT(leftView1));
    if (_walletDic[@"balance"] == nil| _walletDic[@"balance"]==[NSNull null]) {
        leijibutieLable.text = @"账户余额:￥0元";
    }else
    {
        leijibutieLable.text = [NSString stringWithFormat:@"账户余额:￥%0.2f元",_yuENoti.floatValue];
    }
    
    leijibutieLable.tag = 300;
    UIImageView *redLine = [[UIImageView alloc] initWithFrame:CGRectMake(0, HeaderViewSize.height, KWidth, 1)];
    redLine.backgroundColor = [UIColor redColor];
    NSArray *btnTitle = @[@"马上提现",@"查看提现记录"];
    for (int i = 0; i < btnTitle.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        btn.frame = CGRectMake(15+(i*KWidth/2), headerView.frame.size.height/2, KWidth/2-30, headerView.frame.size.height/7);
        btn.backgroundColor = ComColor;
        btn.tag = 100+i;
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btn setTitle:btnTitle[i] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(btnClickedss:) forControlEvents:UIControlEventTouchUpInside];
        btn.layer.masksToBounds = YES;
        btn.layer.cornerRadius = 2;
        [headerView addSubview:btn];
        
        
        if(self.view.frame.size.width == 320)
        {
            tishiLab.font = [UIFont systemFontOfSize: 14];
            btn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        }else if (self.view.frame.size.width == 375)
        {
            tishiLab.font = [UIFont systemFontOfSize: 16];
            btn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        }
        else
        {
            tishiLab.font = [UIFont systemFontOfSize: 17];
            btn.titleLabel.font = [UIFont boldSystemFontOfSize:17];
        }
    }
    NSArray *titleBtn1 = @[@"交易记录",@"补贴记录"];
    for (int j = 0; j<titleBtn1.count; j++) {
        UIButton *baseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        baseBtn.frame = CGRectMake(30+j*(KWidth/2-10), HeaderViewSize.height-5-HeaderViewSize.height/9, KWidth/2-60, HeaderViewSize.height/9);
        //        [baseBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateSelected];
        //        [baseBtn setImageEdgeInsets:<#(UIEdgeInsets)#>]
        baseBtn.tag = 200+j;
        [baseBtn setTitleColor:ComColor forState:UIControlStateSelected];
        [baseBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        
        
        [baseBtn addTarget:self action:@selector(baseBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [headerView addSubview:baseBtn];
        
        if ((_num == 200 && j == 0)||(_num == 201 && j == 1))
        {
            baseBtn.selected = YES;
            if (_num == 200)
            {
                _tishiLabel.hidden = YES;
                _scrollLine = [[UIImageView alloc] initWithFrame:CGRectMake(HeaderViewOrigin.x+30, HeaderViewSize.height-2, baseBtn.frame.size.width, 4)];
                _scrollLine.backgroundColor = ComColor;
            }
            else
            {
                _tishiLabel.hidden = YES;

                _scrollLine.frame = CGRectMake(baseBtn.frame.origin.x+10, HeaderViewSize.height-2, baseBtn.frame.size.width, 4);
                
            }
            [headerView addSubview:_scrollLine];
        }
        else
        {
            baseBtn.selected = NO;
        }
        
        [baseBtn setTitle:titleBtn1[j] forState:UIControlStateNormal];
        if(self.view.frame.size.width == 320)
        {
            baseBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        }else if (self.view.frame.size.width == 375)
        {
            baseBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        }
        else
        {
            baseBtn.titleLabel.font = [UIFont boldSystemFontOfSize:17];
            
        }
        
        
    }
    
    [headerView addSubview:redLine];
    [headerView addSubview:leftView1];
    [headerView addSubview:leftView2];
    [headerView addSubview:leftView3];
    [headerView addSubview:totalTradeLable];
    [headerView addSubview:totalSubsidyLable];
    [headerView addSubview:leijibutieLable];
    [headerView addSubview:lineView];
    
    _tishiLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, headerView.frame.size.height+20, KWidth-200, 20)];
    _tishiLabel.textAlignment = NSTextAlignmentCenter;
    _tishiLabel.font = [UIFont systemFontOfSize:12];
    _tishiLabel.textColor = [UIColor grayColor];
    _tishiLabel.text = @"目前暂无数据";
    _tishiLabel.hidden = YES;
    [_tableview addSubview:_tishiLabel];
    return headerView;
}
-(void)btnClickedss:(UIButton *)sender
{
    
//    NSLog(@"openid == %@",[[NSUserDefaults standardUserDefaults] objectForKey:@"openid"]);
    
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"openid"] isEqualToString:@""]) {
        [self alertView];
        [self.view addSubview:self.hug];
        [self.view addSubview:self.alertView];
    }else
    {
        if (sender.tag == 100) {
            
//            NSLog(@"==== %f",[_walletDic[@"balance"] floatValue]);
            if ([_walletDic[@"balance"] floatValue]<1) {
        
                UIAlertView *alt = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你的余额不足可提现的最低额度" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
                [alt show];
            }
            else
            {
            DMTiXianViewController *tixian = [[DMTiXianViewController alloc] init];
            tixian.yueStr = _yuENoti;
            [self.navigationController pushViewController:tixian animated:YES];
            }
        }
        else
        {
            DMTiXianRecordViewController *tixianRecord = [[DMTiXianRecordViewController alloc] init];
            
            [self.navigationController pushViewController:tixianRecord animated:YES];
        }
        
    }
    
}
-(void)baseBtnClick:(UIButton *)sender
{
    sender.selected = YES;

    UIButton *btn1 = (UIButton *)[self.view viewWithTag:200];
    UIButton *btn2 = (UIButton *)[self.view viewWithTag:201];
    if (sender.tag == 200) {
        _num = 200;
        btn1.selected = YES;
        btn2.selected = NO;
        _scrollLine.frame = CGRectMake(HeaderViewOrigin.x+30, HeaderViewSize.height-2, btn1.frame.size.width, 4);
        [self dataRequest];
        

    }else
    {
        _num = 201;
        btn1.selected = NO;
        btn2.selected = YES;
        _scrollLine.frame = CGRectMake(btn2.frame.origin.x+10, HeaderViewSize.height-2, btn1.frame.size.width, 4);
         [self dataRequest1];
    }
  
    [_tableview reloadData];
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return KHeight/7*3;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    long int number = 0;
    if (_num == 200)
    {
        number = _datas.count;
    }
    else
    {  number = _datas1.count;
    }
    return number;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_num == 200)
    {
        return 75;
    }
    else
    {
        return 75;
    }
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
   
    if (_num == 200) {
        
        static NSString *cellIdentifier = @"Cell";
        
        DMMineViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        DMMineModel *dmModel = _datas[indexPath.row];
        cell.dmModel = dmModel;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    if (_num == 201)
    {
        static NSString *ident = @"Two";
        
        DMMineTwoViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:ident forIndexPath:indexPath];
        DMMineModel *dmModel1 = _datas1[indexPath.row];
        cell1.dmModel = dmModel1;
            cell1.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell1;
    }
    
    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_num == 200)
    {
        [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
        DMOrderDetail *orderDetail = [[DMOrderDetail alloc] init];
        DMMineModel *dmModel = _datas[indexPath.row];
        orderDetail.ordewrID = dmModel.id;
        [self.navigationController pushViewController:orderDetail animated:YES];
    }
}
#pragma mark 自定义UIAlertView
-(UIView *)alertView
{
    if (_alertView == nil) {
        _alertView = [[UIView alloc] initWithFrame:CGRectMake(25 / 375.0 * WINDOWWIDTH, 200, 325 / 375.0 * WINDOWWIDTH, 120)];
        _alertView.backgroundColor = [UIColor whiteColor];
        _alertView.layer.cornerRadius = 8.0;
        UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, _alertView.frame.size.width, 30)];
        titleLabel.text = @"尚未绑定收款微信账号";
        titleLabel.textColor = ComColor;
        titleLabel.font = [UIFont systemFontOfSize:16];
        titleLabel.textAlignment = NSTextAlignmentLeft;
        [_alertView addSubview:titleLabel];
        
        UIButton *cancel = [UIButton buttonWithType:UIButtonTypeCustom];
        cancel.frame = CGRectMake((CGRectGetWidth(_alertView.frame) - 105 / 375.0 *WINDOWWIDTH - 146/ 375.0 *WINDOWWIDTH) / 2.0, CGRectGetHeight(_alertView.frame) - 11 - 48, 100 / 375.0 *WINDOWWIDTH, 38);
        
        cancel.layer.borderWidth = 1;
        //        cancel.layer.borderColor = (__bridge CGColorRef)(ComColor);
        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
        CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 1, 0, 0, 1 });
        
        [cancel.layer setBorderColor:colorref];//边框颜色
        cancel.layer.cornerRadius = 8.0;
        
        [cancel setTitle:@"取消" forState:UIControlStateNormal];
        [cancel setTitleColor:ComColor forState:UIControlStateNormal];
        cancel.titleLabel.font = [UIFont systemFontOfSize:16];
        [_alertView addSubview:cancel];
        
        UIButton *queding = [UIButton buttonWithType:UIButtonTypeCustom];
        queding.frame = CGRectMake(CGRectGetMaxX(cancel.frame) + 51, CGRectGetHeight(_alertView.frame) - 11 - 48, 100 / 375.0 *WINDOWWIDTH, 38);
        
        queding.layer.cornerRadius = 8.0;
        
        [queding setTitle:@"确定" forState:UIControlStateNormal];
        [queding setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        queding.titleLabel.font = [UIFont systemFontOfSize:16];
        queding.backgroundColor = ComColor;
        [queding addTarget:self action:@selector(buttonSelectedBlind:) forControlEvents:UIControlEventTouchUpInside];
        [cancel addTarget:self action:@selector(buttonSelectedBlind:) forControlEvents:UIControlEventTouchUpInside];
        cancel.tag = 135;
        queding.tag = 136;
        [_alertView addSubview:queding];
        
    }
    return _alertView;
}
-(UIView *)hug

{
    if (_hug == nil) {
        _hug = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WINDOWWIDTH, WINDOWHEIGHT)];
        _hug.alpha = 0.6;
        _hug.backgroundColor = [UIColor grayColor];
    }
    return _hug;
}
-(void)buttonSelectedBlind:(UIButton *)sender
{
    [_alertView removeFromSuperview];
    [_hug removeFromSuperview];
    
    if (sender.tag == 136) {
        
        [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:nil completion:^(id result, NSError *error) {
            if (error) {
                [self showMsg:@"授权失败"];
            } else {
                UMSocialUserInfoResponse *resp = result;
                
//                // 授权信息
//                NSLog(@"Wechat uid: %@", resp.uid);
//                NSLog(@"Wechat openid: %@", resp.openid);
//                NSLog(@"Wechat unionid: %@", resp.unionId);
//                NSLog(@"Wechat accessToken: %@", resp.accessToken);
//                NSLog(@"Wechat refreshToken: %@", resp.refreshToken);
//                NSLog(@"Wechat expiration: %@", resp.expiration);
//
//                // 用户信息
//                NSLog(@"Wechat name: %@", resp.name);
//                NSLog(@"Wechat iconurl: %@", resp.iconurl);
//                NSLog(@"Wechat gender: %@", resp.unionGender);
//
//                // 第三方平台SDK源数据
//                NSLog(@"Wechat originalResponse: %@", resp.originalResponse);
                
                [self BindingWeiCahtRequest:resp.openid];
                
            }
        }];
        
        
        
//        UMSocialSnsPlatform *weiChatPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession];
//        
//        weiChatPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response)
//        {
//            NSString *platformName = [UMSocialSnsPlatformManager getSnsPlatformString:UMSocialSnsTypeWechatSession];
//            if ([platformName isEqualToString:UMShareToWechatSession]) {
//                [[UMSocialDataService defaultDataService] requestSocialAccountWithCompletion:^(UMSocialResponseEntity *accountResponse){
////                    NSLog(@"SinaWeibo's user name is %@",[[[accountResponse.data objectForKey:@"accounts"] objectForKey:UMShareToSina] objectForKey:@"username"]);
//                }];
//            }
//            if (response.responseCode == UMSResponseCodeSuccess) {//授权成功
//                
////                UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:platformName];
////                NSLog(@"username is %@, uid is %@, token is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken);
////                NSLog(@"头像:%@",snsAccount.iconURL);
//                
//                //请求获取用户在该平台详细信息,获取返回数据和其他方法一样
//                [[UMSocialDataService defaultDataService] requestSnsInformation:platformName completion:^(UMSocialResponseEntity *accountResponse){
////                     NSLog(@"accountResponse==%@",accountResponse.data[@"openid"]);
//                    NSDictionary *userinfo = [response.data objectForKey:platformName];
//                    NSMutableDictionary *newdict = [NSMutableDictionary dictionary];
//                    [self BindingWeiCahtRequest:accountResponse.data[@"openid"]];
//                    if (userinfo) {
//                        [newdict setDictionary:userinfo];
//                    }
//               
//                }];
//            }
//        });
//        [self BindingWeiCahtRequest];
    }

    
}
-(void)BindingWeiCahtRequest:(NSString *)openid
{
//    NSLog(@"微信openid == %@",openid);

    NSMutableDictionary *weiChatDic = [NSMutableDictionary dictionary];
    [weiChatDic setValue:[AFDownManager MD5String:@"%^&*dongmangoug!@#$weixnBind"] forKey:@"token"];
    [weiChatDic setValue:kkUserDict[@"id"] forKey:@"agent_id"];
    [weiChatDic setValue:openid forKey:@"openid"];
    [weiChatDic setValue:@"weixnBind" forKey:@"action"];
    [AFDownManager POST:BindingWeiChat parameters:weiChatDic success:^(id responseObject) {
//       NSLog(@"微信绑定==%@",responseObject);
        if ([responseObject[@"desc"]  isEqual: @"SUCCESS"]) {
            [[NSUserDefaults standardUserDefaults] setObject:openid forKey:@"openid"];
        }
    } failure:^(NSError *error) {
        [self showMsg:@"绑定失败"];
//        NSLog(@"dataRequest error = %@",error);
        
    }];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
